package cn.gwm.flink.streaming.strategy.vehiclepredict;

import redis.clients.jedis.*;

import java.util.HashSet;

/**
 * @author : GW00280745
 * @date : 2022/5/9 10:12
 * @description :
 */
public class RedisInfo {
    private volatile static RedisInfo instance;
    private JedisPool jedisPool;
    private RedisInfo(){
    }
    public static RedisInfo getInstance() {
        if (instance == null) {
            synchronized (RedisInfo.class) {
                if (instance == null) {
                    instance = new RedisInfo();
                }
            }
        }
        return instance;
    }
    private Jedis jedis;
    public Jedis getClient(){
        jedis = jedisPool.getResource();
        return jedis;
    }
    public JedisCluster jedisPoolAli(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(10);
        jedisPoolConfig.setMaxIdle(4);
        jedisPoolConfig.setMinIdle(4);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(5000);
        jedisPoolConfig.setTestOnBorrow(true);

        HashSet<HostAndPort> set = new HashSet<>();
        //10.31.8.122:7001,10.31.8.122:7002,10.31.8.123:7001,10.31.8.123:7002,10.31.8.124:7001,10.31.8.124:7002
        set.add(new HostAndPort("10.31.8.122",7001));
        set.add(new HostAndPort("10.31.8.122",7002));
        set.add(new HostAndPort("10.31.8.123",7001));
        set.add(new HostAndPort("10.31.8.123",7002));
        set.add(new HostAndPort("10.31.8.124",7001));
        set.add(new HostAndPort("10.31.8.124",7002));
        JedisCluster jedisCluster =
        new JedisCluster(set, 10000, 10000, 100, "a3JLlEg84tNHrCxk", jedisPoolConfig);
        return jedisCluster;
    }
    public JedisCluster jedisPoolInnerNet(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(10);
        jedisPoolConfig.setMaxIdle(4);
        jedisPoolConfig.setMinIdle(4);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(5000);
        jedisPoolConfig.setTestOnBorrow(true);

        HashSet<HostAndPort> set = new HashSet<>();
        set.add(new HostAndPort("10.255.128.239",6379));
        set.add(new HostAndPort("10.255.128.240",6379));
        set.add(new HostAndPort("10.255.128.241",6379));
        set.add(new HostAndPort("10.255.128.242",6379));
        set.add(new HostAndPort("10.255.128.243",6379));
        set.add(new HostAndPort("10.255.128.244",6379));
        return new JedisCluster(set, 10000, 10000, 100, null, jedisPoolConfig);
    }

}
